create or replace function idcard_getAge(p_IDcard varchar2) return integer is

IDcardlen integer;
IDcardyear integer;

begin

  IDcardlen :=Length(trim(p_IDcard));

   if is_idcard(p_IDcard) and IDcardlen = 18 then
     IDcardyear := to_number(substr(p_IDcard,7,4));
  end if;
  if is_idcard(p_IDcard) and IDcardlen = 15 then
     IDcardyear := to_number('19'||substr(p_IDcard,7,2));
  end if;

  return  to_number(to_char(sysdate,'yyyy'))-IDcardyear;


end idcard_getAge;
/
